﻿#region Header

// Majesty of Omega - The next evolution of macro management space strategy
// 
// Copyright 2007-2009 André Claaßen
// 
// This file is protected by the terms and conditions of the
// Microsoft Community License (Ms-CL 1.1), a copy of which should
// have been distributed along with this software. If not,
// you may find the license information at the following URL:
// 
// http://www.microsoft.com/resources/sharedsource/licensingbasics/communitylicense.mspx

#endregion

#region

using System.IO;
using System.Runtime.Serialization.Formatters.Binary;

#endregion

namespace Majesty_of_Omega.Util
{
    /// <summary>
    /// XmlSerializer Helper Class
    /// </summary>
    public class SerializerHelper
    {
        /// <summary>
        /// Saves the object with the binary formatter.
        /// </summary>
        /// <param name="graph">The object graph</param>
        /// <param name="path">The path.</param>
        public static void SaveBinary(object graph, string path)
        {
            FileStream fStream = new FileStream(path, FileMode.Create);

            // Create our binary formatter object.
            BinaryFormatter formatter = new BinaryFormatter();

            // Serialize our data.
            formatter.Serialize(fStream, graph);

            // Close our data file.
            fStream.Close();
        }

        /// <summary>
        /// Loads the object with the binary formatter.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns>the loaded object graph</returns>
        public static object LoadBinary(string path)
        {
            FileStream fStream = new FileStream(path, FileMode.Open);

            // Create our binary formatter object.
            BinaryFormatter formatter = new BinaryFormatter();

            // deserialize our data.
            object o = formatter.Deserialize(fStream);

            // Close our data file.
            fStream.Close();
            return o;
        }
    }
}